# Name: WorkClimate.py - MCBS 10/07/2014
# Description: Loads climate rasters and creates new rasters which merge tiles 33 and 34.

# import system module
import arcpy
from arcpy import env
from arcpy.sa import *

# Set workspace environment:
#env.workspace = "Rasters.gdb"
env.workspace = "C:\Users\Marcelo\Documents\Sugarcane\Offline Data\MunicBasedData\Rasters.gdb"
env.overwriteOutput = True
arcpy.CheckOutExtension("Spatial")

# List of climate variables:
ClimateVar = ["prec", "tmax", "tmin", "tmean"]
Months     = range(1,13)

# ClimateVar = ["prec"]
# Months = [1]

for clim in ClimateVar:

	for m in Months:
		NewClimateRaster = clim + str(m)
		FirstRaster = NewClimateRaster + "_33"
		arcpy.CopyRaster_management(FirstRaster,NewClimateRaster)
		RastersToMosaic = NewClimateRaster + "_34"
		print "Mosaicking " + NewClimateRaster
		arcpy.Mosaic_management(RastersToMosaic,NewClimateRaster,"","", "", "", "", "", "NONE")
		print " "
		
NewAltitudeName = "Altitude"
NewSlopeName    = "Slope"
arcpy.CopyRaster_management("altPrj_33",NewAltitudeName)
arcpy.Mosaic_management("altPrj_34",NewAltitudeName,"","", "", "", "", "", "NONE")
outSlope = Slope(NewAltitudeName, "DEGREE")
outSlope.save(NewSlopeName)
